package com.beyondbit.hr.report.support.render;

import com.beyondbit.hr.report.support.ReportConverter;
import net.sf.jasperreports.engine.JRParameter;
import net.sf.jasperreports.engine.export.JRXlsExporter;
import net.sf.jasperreports.export.ReportExportConfiguration;
import net.sf.jasperreports.export.SimpleXlsReportConfiguration;
import org.springframework.http.MediaType;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class ExcelRender extends AbstractRender<JRXlsExporter>  {
    @Override
    public JRXlsExporter exporter() {
        JRXlsExporter xlsExporter = new JRXlsExporter();
        return xlsExporter;
    }

    @Override
    public List<MediaType> getSupportedMediaTypes() {
        return Arrays.asList(ReportConverter.XLS);
    }

    @Override
    public ReportExportConfiguration defaultReportExportConfiguration() {
        SimpleXlsReportConfiguration xlsReportConfiguration = new SimpleXlsReportConfiguration();
        xlsReportConfiguration.setOnePagePerSheet(false);
        xlsReportConfiguration.setRemoveEmptySpaceBetweenRows(true);
        xlsReportConfiguration.setDetectCellType(false);
        xlsReportConfiguration.setWhitePageBackground(false);

        return xlsReportConfiguration;
    }

    @Override
    public Map<String, Object> defaultReportSettings() {
        Map<String, Object> m =  super.defaultReportSettings();
        m.put(JRParameter.IS_IGNORE_PAGINATION, true);
        return m;
    }

}
